﻿@{
    ViewBag.Title = "收费清单";
    Layout = "~/Areas/PR/Views/Shared/_Layout.cshtml";
}

@section scripts{
    <script type="text/javascript">
    var chargeSum = 0;
    var chargeTotal = 0;
    var ChargeType; //(病历判断是否收费）

    //2018-05-04 zch 收费计算字典
    var PriceOfKM = $("#PriceOfKMId").val();
    var OriginKM = $("#OriginKMId").val();
    var LeastPrice = $("#LeastPriceId").val();
    var FirstAidPrice = $("#FirstAidPriceId").val();

    $(document).ready(function () {
        DisableBackspace();
        initCombo();

        //2016-7-8 zch
        $('#RePrintCharge').linkbutton('disable');
        $.GID("RePrintCharge").style.display = "none";
        if ('@ViewData["RolePermission"]' == "Insert") {
            $('#RePrintCharge').linkbutton('enable');
            $.GID("RePrintCharge").style.display = "block";
        }

        IFCharge();

    });//初始化结束

    function initCombo() {
        $('#txtDDLM').numberbox({
            onChange: function (oldV, newV) {
                var y = $('#txtDDLM').numberbox('getText');
                var z = $('#txtDYLM').numberbox('getText');
                if (z != "") {
                    if (parseFloat(z) >= parseFloat(y)) {
                        var nn = Math.round(parseFloat(z) - parseFloat(y));
                        var n = parseFloat(nn);
                        //if (n <= 3) {
                        //    $('#txtSingleKilometer').numberbox('setValue', 3);
                        //    $('#txtKilometer').numberbox('setValue', 3);

                        //}
                        if ($("#AlarmeventTypeId").val() == '空车') {
                            if (n == 0) {
                                $('#txtSingleKilometer').numberbox('setValue', 0);
                                $('#txtKilometer').numberbox('setValue', 0);
                            }
                        }
                        else {
                            //2018-05-04 zch
                            if (n <= OriginKM) {
                                $('#txtSingleKilometer').numberbox('setValue', OriginKM);
                                $('#txtKilometer').numberbox('setValue', OriginKM);
                            }
                            else {
                                $('#txtSingleKilometer').numberbox('setValue', n);
                                $('#txtKilometer').numberbox('setValue', n);
                            }
                        }
                    } else {
                        $.showMsg("[到点路码]应小于等于[到院路码]！", "提示");
                    }
                }
            }
        });
        $('#txtDYLM').numberbox({
            onChange: function (oldV, newV) {
                var y = $('#txtDDLM').numberbox('getText');
                var z = $('#txtDYLM').numberbox('getText');
                if (y != "") {
                    if (parseFloat(z) >= parseFloat(y)) {
                        var nn = Math.round(parseFloat(z) - parseFloat(y));
                        var n = parseFloat(nn);
                        //2016-7-13 zch
                        if ($("#AlarmeventTypeId").val() == '空车') {
                            if (n == 0) {
                                $('#txtSingleKilometer').numberbox('setValue', 0);
                                $('#txtKilometer').numberbox('setValue', 0);
                            }
                        } else {
                            //2018-05-04 zch
                            if (n <= OriginKM) {
                                $('#txtSingleKilometer').numberbox('setValue', OriginKM);
                                $('#txtKilometer').numberbox('setValue', OriginKM);
                            }
                            else {
                                $('#txtSingleKilometer').numberbox('setValue', n);
                                $('#txtKilometer').numberbox('setValue', n);
                            }
                        }

                    } else {
                        $.showMsg("[到点路码]应小于等于[到院路码]！", "提示");
                    }
                }
            }
        });
        $('#txtKilometer').numberbox({
            onChange: function (oldV, newV) {
                var i = $('#txtKilometer').numberbox('getValue');
                i = Math.round(i);//四舍五入
                //2016-7-13 zch
                if ($("#AlarmeventTypeId").val() == '空车') {
                    if (i == 0) {
                        $('#txtAmbulanceCharge').numberbox('setValue', 0);
                        $('#txtAmbulanceCharge').numberbox('readonly', false);
                    }
                } else {
                    //2018-05-04 zch
                    if (parseFloat(i) <= OriginKM) {
                        $('#txtAmbulanceCharge').numberbox('setValue', LeastPrice);
                    } else {
                        //var c = (parseFloat(i) - 3) * 7 + 30;
                        //2018-05-04 zch
                        var c = (parseFloat(i) - parseFloat(OriginKM)) * parseFloat(PriceOfKM) + Number(LeastPrice);
                        $('#txtAmbulanceCharge').numberbox('setValue', c);
                        //2018-05-04 zch
                        $('#txtPaidCarFee').numberbox('setValue', c);
                    }
                }
            }
        });
        getChargeSum('#txtAmbulanceCharge');
        getChargeSum('#txtWaitCharge');
        getChargeSum('#txtFirstAidCharge');
        getChargeSum('#txtYPTotalFee');
        getChargeSum('#txtCLTotalFee');
        getChargeSum('#txtJCTotalFee');
        getChargeSum('#txtZLTotalFee');
        getChargeSum('#txtbaidufei');
        CraetDataGrid('#YPdatagird', "药品费清单");
        CraetDataGrid('#CLdatagird', "材料费清单");
        CraetDataGrid('#JCdatagird', "检查费清单");
        CraetDataGrid('#ZLdatagird', "治疗费清单");

        var urlstr = '@Url.Content("~/CM/CarBasicInfo/getDictionarybyTypeID?TypeID=PRChargeReason")';  //
        $.EUIcombobox("#txtBackUp1", {
            url: urlstr,
            valueField: 'ID',
            textField: 'Name',
            editable: false,
            OneOption: [{
                ID: "",
                Name: "--请选择--"
            }]
                , onSelect: function (rec) {
                    if (rec.Name == '其他' || rec.Name == '职工用车') {
                        $('#spantxtReason').css("display", "");//显示
                    }
                    else {
                        $('#spantxtReason').css("display", "none");//隐藏
                    }
                }
        });
    }




    function IFCharge() {
        $('#txtNumber').numberbox('readonly', false);//发票号

        ChargeType = $("#ChargeTypeId").val(); //初始收费状态，从病历那边传过来
        //打印收费添加
        $('#PrintCharge').linkbutton({
            onClick: function () {
                openChargePrint();
            }
        });
        //2016-7-8 zch
        $('#RePrintCharge').linkbutton({
            onClick: function () {
                openReChargePrint();
            }
        });

        if (ChargeType == "未收") {
            $('#PrintCharge').linkbutton('disable');
            $.GID("PrintCharge").style.display = "none";
            $('#SaveCharge').linkbutton({
                onClick: function () {
                    submitForm();
                }
            });

            //2016-7-15 zch
            if ($("#AlarmeventTypeId").val() == '空车') {
                $('#txtAmbulanceCharge').numberbox('setValue', 0);
                $('#txtFirstAidCharge').numberbox('setValue', 0);
                $('#txtAmbulanceCharge').numberbox('readonly', false);
                $('#txtFirstAidCharge').numberbox('readonly', false);
            }
                //2018-03-19 zch
            else {
                $('#txtAmbulanceCharge').numberbox('setValue', LeastPrice);
                $('#txtFirstAidCharge').numberbox('setValue', FirstAidPrice);
                $('#txtAmbulanceCharge').numberbox('readonly', true);
                $('#txtFirstAidCharge').numberbox('readonly', true);
            }

            getCharge();
            getChargeTotal();
            document.getElementById("Tchargetype").innerHTML = "当前状态:未收费";

            $('#SaveCharge').linkbutton({
                iconCls: 'icon-custom-cSaveCharge',
                size: 'middle',
                iconAlign: 'top',
                text: '保存收费信息'
            });
            $('#spantxtReason').css("display", "none");//隐藏
        }
            //已收
        else {
            //$('#txtNumber').numberbox('readonly', true); //将发票号变为只读的--20161210注释
            $('#PrintCharge').linkbutton('enable');
            $.GID("PrintCharge").style.display = "block";
            $('#SaveCharge').linkbutton({
                onClick: function () {
                    submitEditForm();
                }
            });
            getEditCharge();
            document.getElementById("Tchargetype").innerHTML = "当前状态:已收费";
            $('#SaveCharge').linkbutton({
                iconCls: 'icon-custom-cSaveCharge',
                size: 'middle',
                iconAlign: 'top',
                text: '提交收费信息'
            });
        }

        //实收发生变化，判断与应收是否不符，控制补充说明的是否required。  放在此处为了先在更新状态下，完成实际收费从数据库取值之前和之后值不一样，会在onchange下误控制补充说明的required。
        $('#txtRealTotalFee').numberbox({
            onChange: function (oldV, newV) {
                if ($('#txtTotalFee').textbox('getValue') != $('#txtRealTotalFee').textbox('getValue')) {

                    document.getElementById('lableReceivablesPaidInconsistentReasons').style.color = "red";
                    //$('#txtBackUp1').combobox({ required: false });
                }
                else {
                    document.getElementById('lableReceivablesPaidInconsistentReasons').style.color = "black";

                }
            }
        });
    }

    function selectbackup1() {
        var value = $('#txtBackUp1').combobox('getText');
        if (value == "其他" || value == "职工用车") {
            $('#spantxtReason').css("display", "");
        }
        else {
            $('#spantxtReason').css("display", "none");//隐藏不符的lable
            $('#txtReceivablesPaidInconsistentReasons').val("");// 清空--不符补充说明
        }
    }

    function CraetDataGrid(cid, titleInfo) {
        $(cid).datagrid({
            title: titleInfo,
            //iconCls: 'icon-custom-Entry',
            scrollbarSize: 18,
            rownumbers: true,
            singleSelect: true,
            width: '98%',
            height: 220,
            fitColumns: true,
            striped: true,
            singleSelect: true,
            loadMsg: '数据加载中请稍后……',
            pagination: false,//启用分页，默认每页10行
            columns: [
                [
               { title: '名称', field: 'Name', width: '35%', sortable: false },
               { title: '收费标注', field: 'ChargeWay', width: '35%', sortable: false },
               { title: '数量', field: 'Counts', width: '13%', sortable: false },
               { title: '总价格', field: 'TotalPrice', width: '14%', sortable: false }
                ]
            ]
        });
    }
    //未收,新增的页面填充取到的值
    function getCharge() {
        $.InitControlDateTime("#txtDate");//20161220
        $.ajax({
            type: 'POST',
            url: '@Url.Content("~/PR/Charge/GetPatientCharge")',
            data:
                {
                    TaskCode: $("#PRID").val(),
                    PatientOrder: $("#PROrderId").val()
                },
            dataType: "json",
            success: function (jsData) {
                //从病历主表取的值

                $('#txtTaskSD').val(jsData.PRInfo.CallOrder ? jsData.PRInfo.CallOrder : '');//任务流水号，不显示
                $('#txtName').textbox('setValue', jsData.PRInfo.Name);
                $('#txtAddressStart').textbox('setValue', jsData.PRInfo.LocalAddress);//起点
                $('#txtAddressEnd').textbox('setValue', jsData.PRInfo.SendAddress);//终点
                //从收费表取值
                if (jsData.listYP.length > 1) {
                    $('#txtYPTotalFee').numberbox('setValue', jsData.listYP[jsData.listYP.length - 1].TotalPrice);
                    $('#YPdatagird').datagrid("loadData", jsData.listYP);
                }
                if (jsData.listCL.length > 1) {
                    $('#txtCLTotalFee').numberbox('setValue', jsData.listCL[jsData.listCL.length - 1].TotalPrice);
                    $('#CLdatagird').datagrid("loadData", jsData.listCL);
                }
                if (jsData.listJC.length > 1) {
                    $('#txtJCTotalFee').numberbox('setValue', jsData.listJC[jsData.listJC.length - 1].TotalPrice);
                    $('#JCdatagird').datagrid("loadData", jsData.listJC);
                }
                if (jsData.listZL.length > 1) {
                    $('#txtZLTotalFee').numberbox('setValue', jsData.listZL[jsData.listZL.length - 1].TotalPrice);
                    $('#ZLdatagird').datagrid("loadData", jsData.listZL);
                }

                //2017-11-09 周志猛 未收的情况下,车费实收默认前3项合计,医疗费实收默认后5项合计
                var a = $('#txtAmbulanceCharge').numberbox('getValue');
                var b = $('#txtWaitCharge').numberbox('getValue');
                var h = $('#txtbaidufei').numberbox('getValue');
                var paidCarSUM = 0; paidCarSUM = Number(a) + Number(b) + Number(h);
                // alert(paidCarSUM);
                $('#txtPaidCarFee').numberbox('setValue', paidCarSUM);

                var c = $('#txtFirstAidCharge').numberbox('getValue');
                var d = $('#txtYPTotalFee').numberbox('getValue');
                var e = $('#txtCLTotalFee').numberbox('getValue');
                var f = $('#txtJCTotalFee').numberbox('getValue');
                var g = $('#txtZLTotalFee').numberbox('getValue');
                var paidPRSUM = 0; paidPRSUM = Number(c) + Number(d) + Number(e) + Number(f) + Number(g);
                //  alert(paidPRSUM);
                $('#txtPaidPRFee').numberbox('setValue', paidPRSUM);
            }
        });
    }
    //已收，编辑的页面填充取到的值
    function getEditCharge() {
        $.ajax({
            type: 'POST',
            url: '@Url.Content("~/PR/Charge/GetPatientCharge")',
            data:
                {
                    TaskCode: $("#PRID").val(),
                    PatientOrder: $("#PROrderId").val()
                },
            dataType: "json",
            success: function (jsData) {
                //从收费表取的值
                $('#txtName').textbox('setValue', jsData.PRInfo.Name);
                //$('#txtName').textbox('setValue', jsData.EditPRInfo.PatientName);
                //$('#txtDate').datetimebox('setText', $.formatTime(jsData.EditPRInfo.Date));//20161220
                //$('#txtDate').datetimebox('setValue', $.formatTime(jsData.EditPRInfo.Date));//20161220
                $('#txtDate').datetimebox('setValue', formateTime2(jsData.EditPRInfo.Date));//20161220
                $('#txtTaskSD').val(jsData.PRInfo.CallOrder);//20161220

                //$('#txtAddressStart').textbox('setValue', jsData.PRInfo.LocalAddress);//起点
                //$('#txtAddressEnd').textbox('setValue', jsData.PRInfo.SendAddress);//终点
                $('#txtAddressStart').textbox('setValue', jsData.EditPRInfo.AddressStart);//20170112改为取收费表--终点
                $('#txtAddressEnd').textbox('setValue', jsData.EditPRInfo.AddressEnd);//终点

                //EditPRInfo是来自IM_PatientChargeDAL的数据。收费表
                $('#txtNumber').numberbox('setValue', jsData.EditPRInfo.InvoiceNumber);
                $('#txtCZLM').numberbox('setValue', jsData.EditPRInfo.OutStationRoadCode);
                $('#txtDDLM').numberbox('setValue', jsData.EditPRInfo.PointRoadCode);
                $('#txtDYLM').numberbox('setValue', jsData.EditPRInfo.ArriveHospitalRoadCode);
                $('#txtDZLM').numberbox('setValue', jsData.EditPRInfo.ReturnStationRoadCode);
                $('#txtSingleKilometer').numberbox('setValue', jsData.EditPRInfo.OneWayKM);
                $('#txtKilometer').numberbox('setValue', jsData.EditPRInfo.ChargeKM);
                $('#txtAmbulanceCharge').numberbox('setValue', jsData.EditPRInfo.CarFee);
                $('#txtWaitCharge').numberbox('setValue', jsData.EditPRInfo.WaitingFee);
                $('#txtFirstAidCharge').numberbox('setValue', jsData.EditPRInfo.EmergencyFee);
                $('#txtRealTotalFee').numberbox('clear');
                $('#txtRealTotalFee').numberbox('setValue', jsData.EditPRInfo.PaidMoney);

                $('#txtPaidCarFee').numberbox('setValue', jsData.EditPRInfo.PaidCarFee); //2017-11-09 周志猛
                $('#txtPaidPRFee').numberbox('setValue', jsData.EditPRInfo.PaidPRFee);   //2017-11-09 周志猛

                $('#txtTotalFee').numberbox('setValue', jsData.EditPRInfo.ReceivableTotal);
                $('#txtBackUp1').combobox('setValue', jsData.EditPRInfo.BackUp1); //2015-11-17 新增不符下拉框内容，与摆渡费
                $('#txtbaidufei').numberbox('setValue', jsData.EditPRInfo.baidufei);
                $('#txtReceivablesPaidInconsistentReasons').textbox('setValue', jsData.EditPRInfo.ReceivablesPaidInconsistentReasons);

                $('#txtIMEI').val(jsData.EditPRInfo.IMEI); //2017-10-27 周志猛

                //2016-1-8  判断编辑的收费内容来源，如果来自pad 就控制不许修改实际收费部分的内容。如果是来自电脑端还是可以修改实际收费的部分的内容的。
                //2017-10-27 周志猛 判断如果收费内容来自PAD ,10个合计全部不许修改
                if (jsData.EditPRInfo.IMEI != '' && jsData.EditPRInfo.IMEI == 'PAD') {
                    //$('#txtRealTotalFee').numberbox('readonly', false); //2017-10-27 被注释
                    //4个合计不随病例改变
                    $('#txtYPTotalFee').numberbox('setValue', jsData.EditPRInfo.DrugFeeTotal); //2017-10-27 周志猛
                    if (jsData.listYP.length > 1) {
                        $('#YPdatagird').datagrid("loadData", jsData.listYP);
                    }
                    $('#txtCLTotalFee').numberbox('setValue', jsData.EditPRInfo.ConsumableFeeTotal);
                    if (jsData.listCL.length > 1) {
                        $('#CLdatagird').datagrid("loadData", jsData.listCL);
                    }
                    $('#txtJCTotalFee').numberbox('setValue', jsData.EditPRInfo.ExamineFeeTotal);
                    if (jsData.listJC.length > 1) {
                        $('#JCdatagird').datagrid("loadData", jsData.listJC);
                    }
                    $('#txtZLTotalFee').numberbox('setValue', jsData.EditPRInfo.MeasureFeeTotal);
                    if (jsData.listZL.length > 1) {
                        $('#ZLdatagird').datagrid("loadData", jsData.listZL);
                    }

                    $('#txtDate').datetimebox('readonly', true);
                    $('#txtNumber').numberbox('readonly', true);
                    $('#txtDDLM').numberbox('readonly', true);
                    $('#txtDYLM').numberbox('readonly', true);
                    $('#txtSingleKilometer').numberbox('readonly', true);
                    $('#txtKilometer').numberbox('readonly', true);
                    $('#txtAmbulanceCharge').numberbox('readonly', true);
                    $('#txtWaitCharge').numberbox('readonly', true);
                    $('#txtFirstAidCharge').numberbox('readonly', true);
                    $('#txtbaidufei').numberbox('readonly', true);
                    $('#txtYPTotalFee').numberbox('readonly', true);
                    $('#txtCLTotalFee').numberbox('readonly', true);
                    $('#txtJCTotalFee').numberbox('readonly', true);
                    $('#txtZLTotalFee').numberbox('readonly', true);
                    $('#txtTotalFee').numberbox('readonly', true);

                    $('#txtRealTotalFee').numberbox('readonly', true);

                    $('#txtPaidCarFee').numberbox('readonly', true); //2017-11-09 周志猛
                    $('#txtPaidPRFee').numberbox('readonly', true);  //2017-11-09 周志猛

                    $('#txtBackUp1').combobox('readonly', false); //应收实收不符原因下拉
                    $('#txtReceivablesPaidInconsistentReasons').textbox('readonly', false);
                }
                else { //非pad情况
                    //4个合计还是跟病例改变
                    if (jsData.listYP.length > 1) {
                        $('#txtYPTotalFee').numberbox('setValue', jsData.listYP[jsData.listYP.length - 1].TotalPrice);
                        $('#YPdatagird').datagrid("loadData", jsData.listYP);
                    }
                    if (jsData.listCL.length > 1) {
                        $('#txtCLTotalFee').numberbox('setValue', jsData.listCL[jsData.listCL.length - 1].TotalPrice);
                        $('#CLdatagird').datagrid("loadData", jsData.listCL);
                    }
                    if (jsData.listJC.length > 1) {
                        $('#txtJCTotalFee').numberbox('setValue', jsData.listJC[jsData.listJC.length - 1].TotalPrice);
                        $('#JCdatagird').datagrid("loadData", jsData.listJC);
                    }
                    if (jsData.listZL.length > 1) {
                        $('#txtZLTotalFee').numberbox('setValue', jsData.listZL[jsData.listZL.length - 1].TotalPrice);
                        $('#ZLdatagird').datagrid("loadData", jsData.listZL);
                    }

                    //2017-10-27 周志猛 增加 病历退回超时提交的判断
                    var TSubmitReturnTime24 = Date.parse(('@ViewBag.TSubmitReturnTime24').replace(/-/g, "/"));
                    var SubmitReturnTime = '';
                    if ('@ViewBag.SubmitReturnTime' != '') {
                        SubmitReturnTime = (('@ViewBag.SubmitReturnTime').replace("/Date(", "").replace(")/", ""));
                    }
                    var boolsubmit;
                    if ('@ViewBag.MedicalStateCode' == '0' || ('@ViewBag.MedicalStateCode' == '2' && SubmitReturnTime > TSubmitReturnTime24)) {
                        boolsubmit = false;
                    }
                    else {
                        boolsubmit = true;
                    }
                }
                //2016-7-8 zch
                if ('@ViewBag.SubmitLogo' == 'true') {
                    //2016-7-13 zch
                    //20170112--增加病种状态为
                    if ('@ViewData["SuperRole"]' == 'SuperRole' || '@ViewBag.MedicalStateCode' == 2) {

                        $('#txtDate').datetimebox('readonly', false);
                        $('#txtNumber').numberbox('readonly', false);
                        $('#txtDDLM').numberbox('readonly', false);
                        $('#txtDYLM').numberbox('readonly', false);
                        $('#txtSingleKilometer').numberbox('readonly', true);
                        $('#txtKilometer').numberbox('readonly', false);
                        $('#txtAmbulanceCharge').numberbox('readonly', false);
                        $('#txtWaitCharge').numberbox('readonly', true);
                        $('#txtFirstAidCharge').numberbox('readonly', false);
                        $('#txtbaidufei').numberbox('readonly', true);
                        $('#txtYPTotalFee').numberbox('readonly', true);
                        $('#txtCLTotalFee').numberbox('readonly', true);
                        $('#txtJCTotalFee').numberbox('readonly', true);
                        $('#txtZLTotalFee').numberbox('readonly', true);
                        $('#txtTotalFee').numberbox('readonly', true);

                        $('#txtRealTotalFee').numberbox('readonly', false);

                        $('#txtPaidCarFee').numberbox('readonly', false); //2017-11-09 周志猛
                        $('#txtPaidPRFee').numberbox('readonly', false);//2017-11-09 周志猛

                        $('#txtBackUp1').combobox('readonly', false);
                        $('#txtReceivablesPaidInconsistentReasons').textbox('readonly', false);
                    }
                    else if ('@ViewData["SuperRole"]' == 'SuperRole' && jsData.EditPRInfo.IMEI != '' && jsData.EditPRInfo.IMEI == 'PAD') {
                        $('#txtRealTotalFee').numberbox('readonly', false);

                        $('#txtPaidCarFee').numberbox('readonly', false); //2017-11-09 周志猛
                        $('#txtPaidPRFee').numberbox('readonly', false);  //2017-11-09 周志猛
                    }
                    else {
                        $('#txtDate').datetimebox('readonly', true);
                        $('#txtNumber').numberbox('readonly', true);
                        $('#txtDDLM').numberbox('readonly', true);
                        $('#txtDYLM').numberbox('readonly', true);
                        $('#txtSingleKilometer').numberbox('readonly', true);
                        $('#txtKilometer').numberbox('readonly', true);
                        $('#txtAmbulanceCharge').numberbox('readonly', true);
                        $('#txtWaitCharge').numberbox('readonly', true);
                        $('#txtFirstAidCharge').numberbox('readonly', true);
                        $('#txtbaidufei').numberbox('readonly', true);
                        $('#txtYPTotalFee').numberbox('readonly', true);
                        $('#txtCLTotalFee').numberbox('readonly', true);
                        $('#txtJCTotalFee').numberbox('readonly', true);
                        $('#txtZLTotalFee').numberbox('readonly', true);
                        $('#txtTotalFee').numberbox('readonly', true);

                        $('#txtRealTotalFee').numberbox('readonly', true);

                        $('#txtPaidCarFee').numberbox('readonly', true); //2017-11-09 周志猛
                        $('#txtPaidPRFee').numberbox('readonly', true);  //2017-11-09 周志猛

                        //2016-7-19 已提交的情况下，如果是手机端上传的收费还是可以修改。
                        if (jsData.EditPRInfo.IMEI != '' && jsData.EditPRInfo.IMEI == 'PAD') {
                            $('#txtBackUp1').combobox('readonly', false);
                            $('#txtReceivablesPaidInconsistentReasons').textbox('readonly', false);

                        } else {
                            $('#txtBackUp1').combobox('readonly', false);
                            $('#txtReceivablesPaidInconsistentReasons').textbox('readonly', false);
                        }
                    }
                }

                //2017-10-27 周志猛  被注释
                //if (jsData.listYP.length > 1) {
                //    $('#txtYPTotalFee').numberbox('setValue', jsData.listYP[jsData.listYP.length - 1].TotalPrice);
                //    $('#YPdatagird').datagrid("loadData", jsData.listYP);
                //}
                //if (jsData.listCL.length > 1) {
                //    $('#txtCLTotalFee').numberbox('setValue', jsData.listCL[jsData.listCL.length - 1].TotalPrice);
                //    $('#CLdatagird').datagrid("loadData", jsData.listCL);
                //}
                //if (jsData.listJC.length > 1) {
                //    $('#txtJCTotalFee').numberbox('setValue', jsData.listJC[jsData.listJC.length - 1].TotalPrice);
                //    $('#JCdatagird').datagrid("loadData", jsData.listJC);
                //}
                //if (jsData.listZL.length > 1) {
                //    $('#txtZLTotalFee').numberbox('setValue', jsData.listZL[jsData.listZL.length - 1].TotalPrice);
                //    $('#ZLdatagird').datagrid("loadData", jsData.listZL);
                //}
                //编辑获取结束判断是否勾选了”其他“，走下面的方法，判断
                selectbackup1();
            }
        });
    }
    //将所有收费项目合计相加。调用该方法动态改变,并赋值给应收合计，实收合计
    function getChargeTotal() {
        var a = $('#txtAmbulanceCharge').numberbox('getValue');
        var b = $('#txtWaitCharge').numberbox('getValue');
        var c = $('#txtFirstAidCharge').numberbox('getValue');
        var d = $('#txtYPTotalFee').numberbox('getValue');
        var e = $('#txtCLTotalFee').numberbox('getValue');
        var f = $('#txtJCTotalFee').numberbox('getValue');
        var g = $('#txtZLTotalFee').numberbox('getValue');
        var h = $('#txtbaidufei').numberbox('getValue');

        chargeTotal = Number(a) + Number(b) + Number(c) + Number(d) + Number(e) + Number(f) + Number(g) + Number(h);
        $('#txtTotalFee').numberbox('setValue', chargeTotal);
        ChargeType = $("#ChargeTypeId").val();
        if (ChargeType == "未收")
        { $('#txtRealTotalFee').numberbox('setValue', chargeTotal); }
        //$('#txtRealTotalFee').numberbox('setValue', chargeTotal);
    }

    //所有numberbox框，改变时，onCharge事件，将同时改变收费总计
    function getChargeSum(cid) {
        $(cid).numberbox({
            onChange: function (oldV, newV) {
                getChargeTotal();
                //var i = $(cid).numberbox('getText');
                //chargeSum = chargeSum + parseFloat(i);
            }
        });
    }
    //新增保存
    function submitForm() {
        //2017-11-09 周志猛 添加车费实收与医疗费实收的合计与实收合计不等的判断
        if (Number($('#txtPaidCarFee').numberbox('getValue')) + Number($('#txtPaidPRFee').numberbox('getValue')) != Number($('#txtRealTotalFee').numberbox('getValue'))) {
            $.messager.confirm('系统检测', '车费应收与医疗费应收合计与实收合计不等,请检查！', function () {

            });
        }
        else {

            if ($('#txtTotalFee').textbox('getValue') != $('#txtRealTotalFee').textbox('getValue')) {
                if ($('#txtBackUp1').combobox('getValue').length == 0) {

                    $.messager.confirm('系统检测', '应收实收不符，请补充说明！', function () {
                    });
                }
                else {
                    if ($('#txtBackUp1').combobox('getText') == '其他' && $('#txtReceivablesPaidInconsistentReasons').textbox('getValue').length == 0) {
                        $.messager.confirm('系统检测', '应收实收不符，请补充说明！', function () {
                        });
                    }
                    else { submitnewtemp(); }
                }
            }
            else {
                submitnewtemp();
            }
        }
    }
    function submitnewtemp() {

        $('#formSubmit').form('submit', {
            url: '@Url.Content("~/PR/Charge/SavePatientCharge")',
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (data) {
                var jsData = $.parseJSON(data);
                //$.handleJsonResult(jsData);
                $.showMsg(jsData.Message, "系统提示", function () { });
                $('#PrintCharge').linkbutton('enable');
                $.GID("PrintCharge").style.display = "block";
                parent.window.opener.bindGrid(); //调用父页面查询方法--刷新
                $("#ChargeTypeId").val("已收");
                IFCharge();
            }
        });
    }

    //更改信息
    function submitEditForm() {
        //console.log($("#IsYB").val());
        if ($("#IsYB").val() == "3" || $("#IsGJM").val() == "2") { //add2021-10-15 医保上线移植 存在医保收费时，Web端不允许更改收费信息//2022-03-28 plq 国家码交易判断
            $.messager.confirm('系统检测', '该笔收费存在医保收费,请联系技术人员修改！是否确认仅修改发票号？', function (r) {
                submitInvoiceNumberEdit(); //add2022-02-21 plq

            });
        }
        else if ($("#IsYL").val() == "3") { //add2022-01-19 银联支付上线移植 存在银联收费时，Web端不允许更改PAD收费信息
            $.messager.confirm('系统检测', '该笔收费存在银联收费,请联系技术人员修改！是否确认仅修改发票号？', function (r) {
                submitInvoiceNumberEdit(); //add2022-02-21 plq
            });
        }
            //2017-11-09 周志猛 添加车费实收与医疗费实收的合计与实收合计不等的判断
        else if (Number($('#txtPaidCarFee').numberbox('getValue')) + Number($('#txtPaidPRFee').numberbox('getValue')) != Number($('#txtRealTotalFee').numberbox('getValue'))) {
            $.messager.confirm('系统检测', '车费应收与医疗费应收合计与实收合计不等,请检查！', function () {

            });
        }
        else {

            if ($('#txtTotalFee').textbox('getValue') != $('#txtRealTotalFee').textbox('getValue')) {
                if ($('#txtBackUp1').combobox('getValue').length == 0) {
                    $.messager.confirm('系统检测', '应收实收不符，请补充说明！', function () {
                    });
                }
                else {
                    if ($('#txtBackUp1').combobox('getText') == '其他' && $('#txtReceivablesPaidInconsistentReasons').textbox('getValue').length == 0) {

                        $.messager.confirm('系统检测', '应收实收不符，请补充说明！', function () {
                        });
                    }
                    else { submittemp(); }
                }
            }
            else {
                submittemp();
            }
        }
    }
    function submittemp() {
        $('#formSubmit').form('submit', {
            url: '@Url.Content("~/PR/Charge/EditPatientCharge")',
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (data) {
                var jsData = $.parseJSON(data);
                // $.handleJsonResult(jsData);
                $.showMsg(jsData.Message, "系统提示", function () { });
            }
        });
    }

     //function:修改发票号提交---存在医保、银联收费时 add2022-02-21 plq
    function submitInvoiceNumberEdit() {
        $('#formSubmit').form('submit', {
            url: '@Url.Content("~/PR/Charge/EditPatientChargeFPH")',
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (data) {
                var jsData = $.parseJSON(data);
                // $.handleJsonResult(jsData);
                $.showMsg(jsData.Message, "系统提示", function () { });
            }
        });
    }

    //打印收费
    function openChargePrint() {
        TaskCode = $("#PRID").val();
        PatientOrder = $("#PROrderId").val();
        AlarmeventType = $("#AlarmeventTypeId").val();
        var SubmitLogo = '@ViewBag.SubmitLogo';//20151218提交标志
        var url = '@Url.Content("~/PR/Print/PatientChargePrint/?TaskCode=")' + encodeURIComponent(TaskCode) + '&PatientOrder=' + PatientOrder + '&AlarmeventType=' + AlarmeventType + '&SubmitLogo=' + SubmitLogo;
        window.open(url); //add2021-10-19 plq 医保上线移植

        //if ($('#txtTotalFee').textbox('getValue') != $('#txtRealTotalFee').textbox('getValue')) {

        //    if ($('#txtBackUp1').combobox('getValue').length == 0) {
        //        $.messager.confirm('系统检测', '应收实收不符，请补充说明！', function () {
        //        });
        //        //  $('#txtReceivablesPaidInconsistentReasons').textbox('enable');
        //    }
        //    else {
        //        submittemp();
        //        window.open(url);
        //    }
        //}
        //else {
        //    submittemp();
        //    window.open(url);
        //}
    }

    //2016-7-8 zch 新增链接 打开重打发票
    function openReChargePrint() {
        TaskCode = $("#PRID").val();
        PatientOrder = $("#PROrderId").val();
        IsYB = $("#IsYB").val(); //add2021-10-15 plq 医保上线移植
        IsGJM = $("#IsGJM").val(); //add2022-03-28 plq 医保国家码上线移植
        var url = '@Url.Content("~/PR/Print/PatientReChargePrint/?TaskCode=")' + encodeURIComponent(TaskCode) + '&PatientOrder=' + PatientOrder + '&IsYB=' + IsYB + '&IsGJM=' + IsGJM;
        window.open(url);
    }

    //20161220--时间格式
    function formateTime2(val) {
        if (val == null) {
            return "无";
        } else {
            var da = new Date(parseInt(val.replace("/Date(", "").replace(")/", "").split("+")[0]));
            var hh = da.getHours() < 9 ? "0" + da.getHours() : da.getHours();
            var mm = da.getMinutes() < 9 ? "0" + da.getMinutes() : da.getMinutes();
            var ss = da.getSeconds() < 9 ? "0" + da.getSeconds() : da.getSeconds();
            return da.getFullYear() + "-" + (da.getMonth() + 1) + "-" + da.getDate() + " " + hh + ":" + mm + ":" + ss;

        }
    }
    </script>
}
<style>
    .DIVHEJI {
        margin: 0 auto;
        height: 30px;
        width: 98%;
        background-color: #afd3fe;
    }
</style>

<form id="formSubmit" method="post">
    <input name="TaskCode" type="hidden" id="PRID" value="@ViewBag.TaskCode" />
    <input name="PatientOrder" type="hidden" id="PROrderId" value="@ViewBag.PatientOrder" />
    <input name="AlarmeventType" type="hidden" id="AlarmeventTypeId" value="@ViewBag.AlarmeventType" />
    <input name="ChargeType" type="hidden" id="ChargeTypeId" value="@ViewBag.ChargeType" />
    <input name="TaskSD" type="hidden" id="txtTaskSD" />
    <input name="IMEI" type="hidden" id="txtIMEI" /><!--2017-10-27 周志猛-->
    <input name="IsYB" type="hidden" id="IsYB" value="@ViewBag.IsYB" />
    <input name="IsGJM" type="hidden" id="IsGJM" value="@ViewBag.IsGJM" />
    <input name="IsYL" type="hidden" id="IsYL" value="@ViewBag.IsYL" />

    @*2018-05-04 zch*@
    <input type="hidden" id="PriceOfKMId" value="@ViewBag.PriceOfKM" />
    <input type="hidden" id="OriginKMId" value="@ViewBag.OriginKM" />
    <input type="hidden" id="LeastPriceId" value="@ViewBag.LeastPrice" />
    <input type="hidden" id="FirstAidPriceId" value="@ViewBag.FirstAidPrice" />



    <div style="width:98%; margin-left:20px; margin-right:20px">
        <div style="margin: 0 0 0 0; width: 98%; height: 50px;">
            @*<table style="vertical-align:middle" border="0">*@
            <table border="0" style="width:inherit">
                <tr>
                    <td width="20%">&nbsp;</td>
                    <td width="10%" align="right">
                        <img src="~/Images/Custom/yiliao.png" style="width:40px;height:40px" />
                    </td>
                    <td width="45%" align="left"><span style="font-weight: bold; font-size: 20pt; margin-top:5px">上海市松江区急救中心院前急救收费清单</span></td>
                    <td width="10%"></td>
                    <td width="15%" valign="bottom"><label id="Tchargetype" style="font-weight: bold; font-size: 11pt;"></label></td>
                </tr>
            </table>
        </div>
        <div class="easyui-panel" title="车辆基础信息" style="width:98%;height:150px;">
            <table border="0" cellpadding="0" cellspacing="0" style="width: 95%; height: 120px; text-align: left; margin-left: 20px; margin-right: 20px">
                <tr>
                    <td align="left" style=" width: 69px;">
                        日期
                    </td>
                    <td colspan="3">
                        <input name="Date" class="easyui-datetimebox" id="txtDate" style="width:150px;" />
                    </td>
                    <td style="width: 8%;">
                        发票号码
                    </td>
                    <td colspan="3">
                        <input name="InvoiceNumber" id="txtNumber" class="easyui-numberbox" style="width:120px;"  /> 
                    </td>
                </tr>
                <tr>
                    <td>
                        姓名
                    </td>
                    <td>
                        <input name="PatientName" id="txtName" class="easyui-textbox" data-options="readonly:true" style="width:120px;" />
                    </td>
                    <td>
                        起讫地点
                    </td>
                    <td colspan="4">
                        <input name="AddressStart" class="easyui-textbox" id="txtAddressStart" style="width:200px;" />至
                        <input name="AddressEnd" class="easyui-textbox" id="txtAddressEnd" style="width:200px;" />
                    </td>
                </tr>
                <tr>
                    <td>
                        出站路码
                    </td>
                    <td>
                        <input name="OutStationRoadCode" id="txtCZLM" class="easyui-numberbox" style="width:100px;" data-options="precision:2">
                    </td>
                    <td>
                        到点路码
                    </td>
                    <td>
                        <input name="PointRoadCode" id="txtDDLM" class="easyui-numberbox" style="width:100px;" data-options="precision:2,required:true ">
                    </td>
                    <td>
                        到院路码
                    </td>
                    <td>
                        <input name="ArriveHospitalRoadCode" id="txtDYLM" class="easyui-numberbox" style="width:100px;" data-options="precision:2,required:true ">
                    </td>
                    <td>
                        返站路码
                    </td>
                    <td>
                        <input name="ReturnStationRoadCode" id="txtDZLM" class="easyui-numberbox" style="width:100px;" data-options="precision:2">
                    </td>
                </tr>
                <tr>
                    <td>单程公里</td>
                    <td><input name="OneWayKM" id="txtSingleKilometer" class="easyui-numberbox" style="width:100px;" data-options="precision:2"></td>
                    <td>收费公里</td>
                    <td><input name="ChargeKM" id="txtKilometer" class="easyui-numberbox" style="width:100px;" data-options="precision:2,required:true"></td>
                    <td colspan="4"></td>
                </tr>
            </table>
        </div>
        <div class="easyui-panel" title="费用清单" style="width:98%;height:60px;">
            <table border="0" cellpadding="0" cellspacing="0" style="width: 95%; text-align: left; margin-left:20px; margin-right:20px">
                <tr style="height: 30px; text-align: center;">
                    <td style="width: 25%">
                        救护车费：
                        <input name="CarFee" id="txtAmbulanceCharge" class="easyui-numberbox" style="color:red;width:100px;" data-options="precision:2,prefix:'￥',required:true">
                    </td>
                    <td style="width: 25%">
                        等车费：
                        <input name="WaitingFee" id="txtWaitCharge" class="easyui-numberbox" style="width:100px;" data-options="precision:2,prefix:'￥'">
                    </td>
                    <td style="width:25%">
                        摆渡费：
                        <input name="baidufei" id="txtbaidufei" class="easyui-numberbox" style="width:100px;" data-options="precision:2,prefix:'￥'">
                    </td>
                    <td style="width: 25%">
                        院前急救费：
                        <input name="EmergencyFee" id="txtFirstAidCharge" class="easyui-numberbox" style="width:100px;" data-options="precision:2,prefix:'￥'">
                    </td>
                </tr>
            </table>
        </div>
        <div class="easyui-panel" style="width:98%;height:260px;">
            <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; height: 250px; text-align: left; margin-top: 5px">
                <tr>
                    <td style="width:25%;" align="center">
                        <table id="YPdatagird"></table>
                    </td>
                    <td style="width:25%;" align="center">
                        <table id="CLdatagird"></table>
                    </td>
                    <td style="width:25%;" align="center">
                        <table id="JCdatagird"></table>
                    </td>
                    <td style="width:25%;" align="center">
                        <table id="ZLdatagird"></table>
                    </td>
                </tr>
                <tr style=" text-align :center; ">
                    <td>
                        <div class="DIVHEJI">
                            药品合计费：
                            <input name="DrugFeeTotal" id="txtYPTotalFee" class="easyui-numberbox" style="width:100px;" data-options="precision:2,prefix:'￥',readonly:true">
                        </div>
                    </td>
                    <td>
                        <div class="DIVHEJI">
                            材料合计费：
                            <input name="ConsumableFeeTotal" id="txtCLTotalFee" class="easyui-numberbox" style="width:100px;" data-options="precision:2,prefix:'￥',readonly:true">
                        </div>
                    </td>
                    <td>
                        <div class="DIVHEJI">
                            检查合计费：
                            <input name="ExamineFeeTotal" id="txtJCTotalFee" class="easyui-numberbox" style="width:100px;" data-options="precision:2,prefix:'￥',readonly:true">
                        </div>
                    </td>
                    <td>
                        <div class="DIVHEJI">
                            治疗合计费：
                            <input name="MeasureFeeTotal" id="txtZLTotalFee" class="easyui-numberbox" style="width:100px;" data-options="precision:2,prefix:'￥',readonly:true">
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="easyui-panel" title="合计费用" style="width:98%;height:120px;">
            <table border="0" cellpadding="0" cellspacing="0" style="width: 95%; height:90px; text-align: left; margin-left:20px; margin-right:20px">
                <tr>
                    <td style="font-weight: bold; font-size: 12pt; margin-top:5px;width:100px">应收费用：</td>
                    <td><input name="ReceivableTotal" id="txtTotalFee" class="easyui-numberbox" style="width: 100px; height: 32px;" data-options="precision:2,prefix:'￥',readonly:true"></td>    
                    <td style="font-weight: bold; font-size: 12pt; color:red">车费实收:</td>
                    <td><input name="PaidCarFee" id="txtPaidCarFee" class="easyui-numberbox" style="width: 100px; height: 32px;" data-options="precision:2,prefix:'￥'"></td>
                    <td style="font-weight: bold; font-size: 12pt; color:red">医疗费实收:</td>
                    <td><input name="PaidPRFee" id="txtPaidPRFee" class="easyui-numberbox" style="width: 100px; height: 32px;" data-options="precision:2,prefix:'￥'"></td>
                    <td style="font-weight: bold; font-size: 12pt; color:red">实际收费：</td>
                    <td><input name="PaidMoney" id="txtRealTotalFee" class="easyui-numberbox" style="width: 100px;height:32px;" data-options="precision:2,prefix:'￥',required:true"></td>
                    <td>
                        <table>
                            <tr>
                                <td> <a href="#" id="SaveCharge" class="easyui-linkbutton" style="width: 100px; font-size: 16pt;"></a></td>
                                <td> <a href="#" id="PrintCharge" class="easyui-linkbutton" data-options="iconCls:'icon-print',size:'middle',iconAlign:'top'" style="width: 100px; font-size: 16pt;">打印</a></td>
                                <td> <a href="#" id="RePrintCharge" class="easyui-linkbutton" data-options="iconCls:'icon-print',size:'middle',iconAlign:'top'" style="width: 100px; font-size: 16pt;">重打发票</a></td>

                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td id="lableReceivablesPaidInconsistentReasons" style="font-weight: bold; font-size: 12pt;">补充说明：</td>

                    <td><input name="BackUp1" id="txtBackUp1" class="easyui-combobox" style="width: 250px; height: 25px;"> </td>
                    <td colspan="3"><span id="spantxtReason"><input name="ReceivablesPaidInconsistentReasons" id="txtReceivablesPaidInconsistentReasons" class="easyui-textbox" style="width: 620px; height: 25px;" data-options="prompt:'请填写其他补充说明！'"></span></td>
                </tr>
            </table>
        </div>
    </div>
</form>
